<?PHP
//??
$username1 = $HTTP_POST_VARS["username"];
$password1 = $HTTP_POST_VARS["password"];

//??????
include("config.php");

//?????????
$query = "Select * from teacher where name='$username1'";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)){
	if ($row["password"] == $password1){
		//tell we want to work with sessions
		session_start();//????
		session_unset();//????
		session_destroy();
		session_register("pass");//??????,????
		$HTTP_SESSION_VARS["pass"] = $password1;
		session_register("id");//?????
		$HTTP_SESSION_VARS["id"] = $username1;
		//???????
		header("Location: index.php");
		setcookie('cookiepass',$password1);
		setcookie('cookieid',$username1);
	}
	else{
	//????
	makeform($incorrectLogin);
	}
}
else{
	//
	if ($username1 == ""){
		makeform("");//
	}
	else{
		makeform($incorrectLogin);//
	}
}

//
function makeform($errormessage="", $username2 = ""){

	echo $errormessage;}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>LOG-IN</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h1>????</h1>
<?PHP
if ($errormessage != ""){echo "<font color=\"#FF0000\"><strong>$errormessage</strong></font><br>";} 
?>
<form name="form1" method="post" action="login.php">
	<p>???:
	<input name="username" type="text" id="username" value=<?PHP 
	echo "\"$uername2\"";
	if ($username2 != ""){echo "DISABLED";}
	?> >
	<br>
	?&nbsp;&nbsp;?:
	<input name="password" type="password" id="password"><br>
	<br>
	<input type="submit" value="??">
	???????,????<a href="signup.php">here</a>??.</p>
</form>
</body>
</html>